import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  Query,
} from '@nestjs/common';
import { WireService } from './wire.service';
import { CreateWireDto } from './dto/create-wire.dto';
import { UpdateWireDto } from './dto/update-wire.dto';
import { v4 } from 'uuid';

@Controller('wire')
export class WireController {
  constructor(private readonly wireService: WireService) {}

  @Post()
  create(@Body() createWireDto: CreateWireDto) {
    return this.wireService.create(createWireDto);
  }

  @Post('many')
  async createMany(@Body() args: any) {
    const data = args.map((item) => {
      return {
        ...item,
        projId: +item.projId,
        show: 0,
        remain: item.long,
      } as CreateWireDto;
    });
    return await this.wireService.createMany(data);
  }

  @Get()
  async findAll(@Query() args = {}) {
    return await this.wireService.findAll(args);
  }

  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.wireService.findOne(+id);
  }

  @Patch(':id')
  update(@Param('id') id: string, @Body() updateWireDto: UpdateWireDto) {
    return this.wireService.update(+id, updateWireDto);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.wireService.remove(+id);
  }
}
